package bme.andraskindler.treenventory.fragment;

import bme.andraskindler.treenventory.activity.CameraActivity;
import bme.andraskindler.treenventory.activity.OptionsActivity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.widget.Toast;

/**
 * A felbontás gyorsbeállítására szolgáló dialog, a {@link CameraActivity}-ben használom.
 * 
 * @author andraskindler
 * 
 */
public class ResolutionFragment extends DialogFragment {

	@Override
	public Dialog onCreateDialog(Bundle savedInstanceState) {
		final String[] items = { "Alacsony", "Normál", "Magas" };

		AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
		builder.setTitle("Válassz felbontást");
		builder.setItems(items, new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int item) {
				final SharedPreferences preferences = getActivity().getSharedPreferences(OptionsActivity.SETTINGS, Context.MODE_PRIVATE);
				preferences.edit().putInt(OptionsActivity.SETTINGS_RESOLUTION, item).commit();
				Toast.makeText(getActivity(), items[item] + " kiválasztva", Toast.LENGTH_SHORT).show();
			}
		});
		return builder.create();
	}

	public ResolutionFragment() {
		super();
	}

	public static ResolutionFragment newInstance() {
		return new ResolutionFragment();
	}

}
